package com.wgy.day26.LinkedHashMap;

import java.util.HashMap;
import java.util.LinkedHashMap;

/*
java.util.LinkedHashMap<k,v>集合 extends HashMap<k,v>集合

LinkedHashMap的特点:
            1.LinkedHashMap集合底层哈希表+链表(保证迭代的顺序)
            2.LinkedHashMap集合是一个有序的集合,存储元素和取出元素的顺序是一致的
*/
public class Demo01LinkedHashMap {
    public static void main(String[] args) {
        HashMap<String,String> map=new HashMap<>();
        map.put("a","a");
        map.put("d","D");
        map.put("b","B");
        map.put("a","A");
        System.out.println(map); //key不允许重复,无序的{a=A, b=B, d=D}

        LinkedHashMap<String,String> linked=new LinkedHashMap<>();
        linked.put("a","a");
        linked.put("d","D");
        linked.put("b","B");
        linked.put("a","A");
        System.out.println(linked);//key不允许重复, 有序的  {a=A, d=D, b=B}

    }
}
